#ifndef __DS__
#define __DS__

#include "Type_Define.h"
#include "IO_LINK_Global_Param.h"

//定义DS_Object_Table在FlashRom上的存储地址
//DS_Object_Table组成为：
/******
 *    DS_Object_Table总长度（自定义 uint16）
 *    Header（Table G2)
 *    DS_Object (Table G1)
 * 
 * 
 * **************/
//DS_Object_Table_FlashAddress
#define DS_FLASH_ROM_ADDRESS(i)                FLASHBASE_ADDRESS+i*2062  // DS_Object_Table首地址，也为总长度地址
#define DS_TOTAL_LENGTH_FLASH_ADDRESS(i)         FLASHBASE_ADDRESS+i*2062   //总长度保存地址 
#define DS_HEADER_FLASH_ADDRESS(i)         FLASHBASE_ADDRESS+i*2062+2  //Header地址
#define DS_CHECKSUM_FLASH_ADDRESS(i)       FLASHBASE_ADDRESS+i*2062+2   //Checksum地址
#define DS_ENTRYS_FLASH_ADDRESS(i)         FLASHBASE_ADDRESS+i*2062+14  //Entrys地址
 
typedef struct{
  uint32_t Parameter_Checksum;
  uint16_t VendorID;
  uint32_t DeviceID;
  uint16_t FunctionID;
}DS_Object_Header_TYPE;
 
typedef  struct{
      uint16_t Len; //存储在Flash中的总长度
      DS_Object_Header_TYPE Header;
       uint8_t DS_Object_Data[0];
}DS_Object_Table_TYPE;  //单个条目DS Object
 
typedef struct 
{
   uint16_t ISDU_Index;
   uint8_t  ISDU_Subindex;
   uint8_t ISDU_Length;
   uint8_t ISDU_Data[0];
}DS_Object_Entry_TYPE;

 

typedef enum{
   DS_CheckActivationState_0,
   DS_WaitingOnDSActivity_1,
   DS_UpDownLoad_2,
   DS_Off_3

}DS_STATE_TYPE;

typedef enum{
  DS_sub_None,
  DS_sub_Checkidentity_4,
  DS_sub_CheckMemSize_5,
  DS_sub_CheckUpload_6,
  DS_sub_CheckDSValidity_8,
 // DS_sub_Upload_7**********************************
    DS_sub_Upload_Decompose_IL_13,
    DS_sub_Upload_ReadParameter_14,
    DS_sub_Upload_Upload_Fault_16,
    DS_sub_Upload_StoreDataSet_15,
  //DS_sub_Upload_7*******************
  
  DS_sub_CheckChecksum_9,
  //DS_sub_Download_10*********************************
    DS_sub_Download_Decompose_Set_17,
    DS_sub_Dwonload_Write_Parameter_18,
    DS_sub_Download_Download_Done_19,
    DS_sub_Download_Download_Fault_20,

  //DS_sub_Download_10********************************
  DS_sub_Ready_11,
  DS_sub_Fault_12
}DS_sub_STATE_TYPE;

 


extern BOOL DS_Enable_Flag[PORT_NUM]; //控制变量，控制DS是否使能
extern BOOL DS_UploadEnable_Flag[PORT_NUM]; //控制变量，控制参数能否上传
extern BOOL DS_DownLoad_Flag[PORT_NUM]; //控制变量，控制参数能否下载

#endif

